package com.net.shop.car.manager.ui.personalcenter.oil;

import java.util.ArrayList;
import java.util.Stack;

import org.json.JSONException;
import org.json.JSONObject;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.RequestQueue;
import com.net.shop.car.manager.Constant;
import com.net.shop.car.manager.R;
import com.net.shop.car.manager.api.model.CardItem;
import com.net.shop.car.manager.api.model.Member;
import com.net.shop.car.manager.api.model.OilDetailInfo;
import com.net.shop.car.manager.api.volley.VolleyCenter;
import com.net.shop.car.manager.api.volley.VolleyListenerImpl;
import com.net.shop.car.manager.api.volley.request.oil.OilCardBindRequest;
import com.net.shop.car.manager.api.volley.request.oil.OilCardDeletrRequest;
import com.net.shop.car.manager.api.volley.request.oil.OilCardRequest;
import com.net.shop.car.manager.api.volley.request.oil.OilChargeRequest;
import com.net.shop.car.manager.api.volley.request.oil.OilHuaBoRequest;
import com.net.shop.car.manager.api.volley.request.oil.OilJifenRequest;
import com.net.shop.car.manager.api.volley.response.oil.OilCardBindResponse;
import com.net.shop.car.manager.api.volley.response.oil.OilCardDeletResponse;
import com.net.shop.car.manager.api.volley.response.oil.OilChargeResponse;
import com.net.shop.car.manager.api.volley.response.oil.OilHuaBoResponse;
import com.net.shop.car.manager.api.volley.response.oil.OilJifenResponse;
import com.net.shop.car.manager.api.volley.response.oil.OildCardResponse;
import com.net.shop.car.manager.ui.FullScreenDialog;
import com.net.shop.car.manager.ui.adapter.OilCardDetailAdapter;
import com.net.shop.car.manager.ui.adapter.OildQuiryAdapter;

/**
 * 
 * @author tucheng this is dialog to show oild detail
 * 
 */

public class OildCardDialog extends FullScreenDialog implements
		android.view.View.OnClickListener {
	// 将所有布局全部填充至View 总共有八个页面所以有八个View
	View oild_bind;
	View oild_charge;
	View oild_qury;
	View huabo;
	View head;
	View oild_bind_dialog;

	/**
	 * @deprecated there are quiry params
	 */
	Dialog dialog;
	RequestQueue queue;
	ListView list_qury;
	OildQuiryAdapter adapter;
	ArrayList<CardItem> arrayList;
	JSONObject json;
	// 返回
	ImageView back;
	// 每一项的姓名 卡号
	CardItem item;
	// 处理类Dialog
	MyHandler handler;
	// 积分订单类
	JiFenOrder jifen;
	// 充值
	boolean IsClick = true;
	//得到ID
	public Member user;
	// 记录上一个点击事件图片是否已经被点击
	public String ID;
	int last;
	Button twohundred = null;
	Button fourhundred;
	Button thounds;
	EditText monney;
	TextView sumJiFeng;
	TextView ConsumJiFen;
	Button OtherCharge;
	// 其他账号充值
	EditText cardNameEdit;
	EditText cardNumberEdit;
	EditText monneyEdit;
	// 提示错误信息
	TextView tishi;
	// 绑定提交按钮
	Button Submit;
	// 绑定详情
	TextView CardBind;
	// 油卡绑定提交监听
	// 绑定详情
	Button OilBind;
	// 总共积分
	String sumjifen = "200";
	// 划拨详情界面list；
	ArrayList<OilDetailInfo> oildetail;
	private String caocanIndex[] = new String[] { "一", "二", "三", "四", "五", "六",
			"七", "八", "九", "十", "十一", "十二", "十三", "十四", "十五" };

	public static final String GET_URL = "http://tapi.clejw.com/mobile/interface.do?";

	Context context;
	LayoutInflater inflater = getLayoutInflater();
	Stack<View> stack;

	public OildCardDialog(Context context,Member user) {
		super(context, R.style.Dialog_Fullscreen);
		this.context = context;
		this.user=user;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		
		inti();
		handler = new MyHandler();
		super.onCreate(savedInstanceState);
	}

	// 油卡查询 首页
	private void inti() {
		ID=user.getMemberId();
		System.out.println("==========================>"+ID);
		head = inflater.inflate(R.layout.oild_card_dialog, null);
		setContentView(head);
		back(head);
		stack = new Stack<View>();
		jifen = new JiFenOrder();
		stack.push(head);
		System.out.println("------------------>" + stack.size());
		ImageView charge = (ImageView) this.findViewById(R.id.oild_charge_img);
		ImageView qury = (ImageView) this.findViewById(R.id.oild_qury);
		TextView bind = (TextView) this.findViewById(R.id.oild_bind);
		initTitle(findViewById(R.id.message_title), activity.getResources()
				.getString(R.string.personal_oild));
		bind.setOnClickListener(this);
		charge.setOnClickListener(this);
		qury.setOnClickListener(this);

	}

	/**
	 * 方法oild_qury有int型数 是为了区分适配器是哪一个listView调用
	 */
	@Override
	public void onClick(View arg0) {
		switch (arg0.getId()) {

		// 查询监听
		case R.id.oild_qury:
			dialog = ProgressDialogUtil.showProgressDialog(context, "", "",
					true);
			new MyThread().start();
			oild_charge = inflater.inflate(R.layout.oild_new_charge, null);
			// 填充查询界面
			oild_qury = inflater.inflate(R.layout.oild_card_quiry, null);
			setContentView(oild_qury);
			stack.push(oild_qury);
			back(oild_qury);
			list_qury = (ListView) oild_qury.findViewById(R.id.oild_quiry_list);
			CardBind = (TextView) oild_qury.findViewById(R.id.oild_quiry_other);
			CardBind.setOnClickListener(this);
			oild_qury(1);
			oild_quiry_initView();
			break;
		// 油卡绑定
		case R.id.oild_quiry_other:
			oild_bind_dialog = inflater.inflate(R.layout.oild_card_bind_dialog,
					null);
			setContentView(oild_bind_dialog);
			OilBind = (Button) oild_bind_dialog.findViewById(R.id.card_submit);
			OilBind.setOnClickListener(this);
			stack.push(oild_bind_dialog);
			back(oild_bind_dialog);
			break;

		// 油卡绑定提交监听
		case R.id.card_submit:
			String name = ((EditText) oild_bind_dialog
					.findViewById(R.id.edit_name)).getText().toString();
			String number = ((EditText) oild_bind_dialog
					.findViewById(R.id.edit_number)).getText().toString();
			OilBind(number, name);
			break;
		// 充值监听
		case R.id.oild_charge_img:
			oild_charge = inflater.inflate(R.layout.oild_new_charge, null);
			new MyThread().start();
			setContentView(oild_charge);
			dialog = ProgressDialogUtil.showProgressDialog(context, "", "",
					true);
			stack.push(oild_charge);
			back(oild_charge);
			System.out.println("------------------>" + stack.size());
			charge_init();
			oild_qury(2);
			// 获取总积分
			getOilJiFen();

			list_qury.setOnItemClickListener(new OnItemClickListener() {

				@Override
				public void onItemClick(AdapterView<?> parent, View view,
						int position, long id) {
					if (last == position) {
						if (IsClick == true) {
							IsClick = false;
						} else {
							IsClick = true;
						}
					}
					final ImageView img = (ImageView) view
							.findViewById(R.id.oild_selected);
					jifen.number = (String) ((TextView) view
							.findViewById(R.id.oild_number)).getText();
					jifen.Name = (String) ((TextView) view
							.findViewById(R.id.oild_name)).getText();
					jifen.Id = arrayList.get(position).getMemberId();

					System.out.println("卡号    " + jifen.number + "名字      "
							+ jifen.Name + "ID    " + jifen.Id);

					int lenth = parent.getChildCount();
					View view1;
					for (int i = 0; i < lenth; i++) {
						view1 = parent.getChildAt(i);
						if (view1 != view) {
							((ImageView) view1.findViewById(R.id.oild_selected))
									.setImageResource(R.drawable.notselected);
						} else if (IsClick) {
							((ImageView) view1.findViewById(R.id.oild_selected))
									.setImageResource(R.drawable.selected);

						} else {
							((ImageView) view1.findViewById(R.id.oild_selected))
									.setImageResource(R.drawable.notselected);
							jifen.monney = "";
							jifen.Name = "";
							jifen.number = "";

						}
					}
					last = position;
				}

			});

			break;
		case R.id.oild_other_charge:
			LinearLayout line = (LinearLayout) oild_charge
					.findViewById(R.id.list2);
			list_qury.setVisibility(View.GONE);
			OtherCharge.setVisibility(View.GONE);
			line.setVisibility(View.VISIBLE);
			// 填充充值其他账号页面
			System.out.println("------------------>" + stack.size());
			break;

		case R.id.twohundred:
			twohundred.setBackgroundResource(R.drawable.oil_charge_img);
			thounds.setBackgroundResource(R.drawable.anniu2);
			fourhundred.setBackgroundResource(R.drawable.anniu2);
			jifen.monney = "20000";
			monney.setText("200");
			monney.setTextColor(Color.BLACK);
			ConsumJiFen.setText("20000");
			ConsumJiFen.setTextColor(Color.RED);
			break;
		case R.id.fourhundred:
			twohundred.setBackgroundResource(R.drawable.anniu2);
			thounds.setBackgroundResource(R.drawable.anniu2);
			fourhundred.setBackgroundResource(R.drawable.oil_charge_img);
			jifen.monney = "40000";
			monney.setText("400");
			monney.setTextColor(Color.BLACK);
			ConsumJiFen.setText("40000");
			ConsumJiFen.setTextColor(Color.RED);
			break;

		case R.id.thounds:
			twohundred.setBackgroundResource(R.drawable.anniu2);
			thounds.setBackgroundResource(R.drawable.oil_charge_img);
			fourhundred.setBackgroundResource(R.drawable.anniu2);
			monney.setText("1000");
			monney.setTextColor(Color.BLACK);
			jifen.monney = "100000";
			ConsumJiFen.setText("100000");
			ConsumJiFen.setTextColor(Color.RED);
			oild_bind_dialog = inflater.inflate(R.layout.oild_card_bind_dialog,
					null);
			break;
		// 复用布局 将有用的显示 无用的隐藏

		// 油卡绑定监听
		case R.id.oild_bind:

			dismiss();
			break;

		// 油卡充值之后 付款监听
		case R.id.oild_new_charge_btn:
			isCharge();

			break;

		case R.id.title_back_btn:
			stack.pop();
			if (stack.size() >= 1) {
				setContentView(stack.firstElement());
				jifen.Id = null;
				jifen.Name = null;
				jifen.monney = null;
				System.out.println("------------------>" + stack.size());
			} else {
				stack.clear();
				dismiss();
			}

			break;
		}

	}

	public void oild_quiry_initView() {
		// 填充划拨界面
		huabo = inflater.inflate(R.layout.oild_card_huabo, null);
		list_qury.setOnItemLongClickListener(new OnItemLongClickListener() {

			@Override
			public boolean onItemLongClick(AdapterView<?> parent, View view,
					final int position, long id) {
				createDialog(position, 1);
				return false;
			}
		});
		list_qury.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				dialog = ProgressDialogUtil.showProgressDialog(context, "", "",
						true);
				new MyThread().start();
				getOildHuabo(arrayList.get(position).getId(), huabo);
				setContentView(huabo);
				stack.push(huabo);
				back(huabo);
				System.out.println("------------------>" + stack.size());

			}
		});
	}

	public void oild_qury(final int i) {
		if (i == 1) {
			ReceiveBroadCast receiveBroadCast = new ReceiveBroadCast();
			IntentFilter filter = new IntentFilter();
			filter.addAction("data"); // 只有持有相同的action的接受者才能接收此广播
			context.registerReceiver(receiveBroadCast, filter);
		}

		VolleyCenter.getVolley()
				.addGetRequest(
						new OilCardRequest(ID),
						new VolleyListenerImpl<OildCardResponse>(
								new OildCardResponse()) {

							@Override
							public void deleveryResponse(
									OildCardResponse response) {
								ProgressDialogUtil.cancleProgressDialog(dialog);
								arrayList = response.arrayList;
								adapter = new OildQuiryAdapter(context,
										arrayList, OildCardDialog.this, i);
								list_qury.setAdapter(adapter);
							}
						});

	}

	/**
	 * 此方法为油卡删除界面
	 * 
	 * @param position
	 */

	public void OildDelete(final int position) {
		VolleyCenter.getVolley().addGetRequest(
				new OilCardDeletrRequest(arrayList.get(position).getId(), ID),
				new VolleyListenerImpl<OilCardDeletResponse>(
						new OilCardDeletResponse()) {
					@Override
					public void deleveryResponse(OilCardDeletResponse response) {
						arrayList.remove(position);
						adapter.notifyDataSetChanged();
					}
				});
	}

	private void getOilJiFen() {
		VolleyCenter.getVolley()
				.addGetRequest(
						new OilJifenRequest(ID),
						new VolleyListenerImpl<OilJifenResponse>(
								new OilJifenResponse()) {

							@Override
							public void deleveryResponse(
									OilJifenResponse response) {
								if (response.isSuccess()) {
									sumjifen = response.flag;
									sumJiFeng.setText(response.flag);
								}

							}
						});

	}

	public void OilBind(String number, String name) {
		VolleyCenter.getVolley().addGetRequest(
				new OilCardBindRequest(ID, number, name),
				new VolleyListenerImpl<OilCardBindResponse>(
						new OilCardBindResponse()) {

					@Override
					public void deleveryResponse(OilCardBindResponse response) {
						if (response.isSuccess()) {
							createDialog(0, 3);
						}

					}
				});
	}

	public void getOildHuabo(String number, final View view) {
		VolleyCenter.getVolley()
				.addGetRequest(
						new OilHuaBoRequest(number),
						new VolleyListenerImpl<OilHuaBoResponse>(
								new OilHuaBoResponse()) {

							@Override
							public void deleveryResponse(
									OilHuaBoResponse response) {
								ProgressDialogUtil.cancleProgressDialog(dialog);
								TextView pgname = (TextView) view
										.findViewById(R.id.pgname);
								TextView pgtype = (TextView) view
										.findViewById(R.id.pgtype);// 到账日期
								TextView pgmoney = (TextView) view
										.findViewById(R.id.pgmoney);// 钱数
								TextView pgpici = (TextView) view
										.findViewById(R.id.pgpici);// 划拨期数

								ListView taocan_huabo_xiangqing = (ListView) view
										.findViewById(R.id.oild_huabo_list);// 套餐划拨详情
								TextView text = (TextView) view
										.findViewById(R.id.oil_huabo_text);
								// 判断是否成功 并判断Content内有无数据
								if (response.isSuccess()
										&& !response.Content.equals("[]")) {
									pgtype.setText(response.card.Date + "");
									pgname.setText("套餐业务" + caocanIndex[0]);
									pgmoney.setText("￥" + response.card.Monney);
									pgpici.setText(response.card.Times + "次");
									OilCardDetailAdapter adapter = new OilCardDetailAdapter(
											context, response.list);
									taocan_huabo_xiangqing.setAdapter(adapter);
								} else {
									taocan_huabo_xiangqing
											.setVisibility(View.GONE);
									text.setVisibility(View.VISIBLE);
									pgtype.setText("当前油卡没有日期数据");
									pgname.setText("套餐业务" + caocanIndex[0]);
									pgmoney.setText("未获取到余额数据");
									pgpici.setText("未获取到划拨次数数据");
								}

							}
						});

	}

	private void OilCharge() {
		VolleyCenter.getVolley().addGetRequest(
				new OilChargeRequest(ID, jifen.number, jifen.Name,
						jifen.monney),
				new VolleyListenerImpl<OilChargeResponse>(
						new OilChargeResponse()) {

					@Override
					public void deleveryResponse(OilChargeResponse response) {
						if (response.flag.equals("success")) {
							getOilJiFen();
						}
					}
				});
	}

	// 积分充值初始化
	private void charge_init() {
		Button oild_charge_btn = (Button) oild_charge
				.findViewById(R.id.oild_new_charge_btn);
		list_qury = (ListView) oild_charge.findViewById(R.id.oild_pay_new_list);

		OtherCharge = (Button) oild_charge.findViewById(R.id.oild_other_charge);
		twohundred = (Button) oild_charge.findViewById(R.id.twohundred);
		fourhundred = (Button) oild_charge.findViewById(R.id.fourhundred);
		thounds = (Button) oild_charge.findViewById(R.id.thounds);

		cardNumberEdit = (EditText) oild_charge
				.findViewById(R.id.oild_card_number);
		cardNameEdit = (EditText) oild_charge.findViewById(R.id.oild_card_name);
		monney = (EditText) oild_charge.findViewById(R.id.other_monney);

		final TextView cardName = (TextView) oild_charge
				.findViewById(R.id.oil_charge_text2);
		final TextView cardNumber = (TextView) oild_charge
				.findViewById(R.id.oil_charge_text1);
		sumJiFeng = (TextView) oild_charge.findViewById(R.id.sum_jifen);
		ConsumJiFen = (TextView) oild_charge.findViewById(R.id.consum_jifen);
		tishi = (TextView) oild_charge.findViewById(R.id.tishi);

		OtherCharge.setOnClickListener(this);
		twohundred.setOnClickListener(this);
		fourhundred.setOnClickListener(this);
		thounds.setOnClickListener(this);
		monney.setOnClickListener(this);
		sumJiFeng.setOnClickListener(this);
		ConsumJiFen.setOnClickListener(this);
		oild_charge_btn.setOnClickListener(this);
		// 油卡号监听
		cardNumberEdit.addTextChangedListener(new TextWatcher() {
			@Override
			public void onTextChanged(CharSequence s, int start, int before,
					int count) {
				cardNumber.setText(s);
				jifen.number = s.toString();
				System.out.println("==========================>" + s);
			}

			@Override
			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {
			}

			@Override
			public void afterTextChanged(Editable s) {
			}
		});
		// 充值姓名监听
		cardNameEdit.addTextChangedListener(new TextWatcher() {

			@Override
			public void onTextChanged(CharSequence s, int start, int before,
					int count) {
				cardName.setText(s);
				jifen.Name = s.toString();
				System.out.println("==========================>" + s);
			}

			@Override
			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {

			}

			@Override
			public void afterTextChanged(Editable s) {

			}
		});
		// 充值钱数监听
		monney.addTextChangedListener(new TextWatcher() {

			@Override
			public void onTextChanged(CharSequence s, int start, int before,
					int count) {
				ConsumJiFen.setText(s + "00");
				monney.setTextColor(Color.BLACK);
				ConsumJiFen.setTextColor(Color.RED);
			}

			@Override
			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {
			}

			@Override
			public void afterTextChanged(Editable s) {
				jifen.monney = ConsumJiFen.getText() + "";
			}
		});
	}

	void createDialog(final int position, int i) {
		final Dialog OilDialog = new Dialog(context);
		OilDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
		View view = inflater.inflate(R.layout.oil_sure_dialog, null);
		OilDialog.setContentView(view);
		final TextView text = (TextView) view.findViewById(R.id.oil_msg);
		final TextView title = (TextView) view.findViewById(R.id.oil_title);
		final TextView back = (TextView) view.findViewById(R.id.oil_back);
		Button consure = (Button) view.findViewById(R.id.oil_sure);
		Button cancle = (Button) view.findViewById(R.id.oil_cancle);
		final LinearLayout line = (LinearLayout) view.findViewById(R.id.line);

		switch (i) {
		case 1:
			line.setVisibility(View.VISIBLE);
			back.setVisibility(View.GONE);
			title.setText("删除提示");
			text.setText("您确定删除此张油卡\n姓名； " + arrayList.get(position).getName()
					+ "\n油卡号；   " + arrayList.get(position).getId());
			consure.setOnClickListener(new View.OnClickListener() {

				@Override
				public void onClick(View v) {
					OildDelete(position);
					line.setVisibility(View.GONE);
					back.setVisibility(View.VISIBLE);
					title.setText("恭喜你，删除成功");
					text.setText("恭喜你。。。。成功删除此张油卡");
					
				}
			});
			cancle.setOnClickListener(new View.OnClickListener() {

				@Override
				public void onClick(View v) {
					OilDialog.dismiss();
				}
			});
			break;
		case 2:
			line.setVisibility(View.VISIBLE);
			back.setVisibility(View.GONE);
			title.setText("充值提示");
			text.setText("您确定充值此张油卡\n\n\n姓名； " + jifen.Name + "\n\n\n油卡号；   "
					+ jifen.number + "\n\n\n充值金额" + jifen.monney);
			consure.setOnClickListener(new View.OnClickListener() {

				@Override
				public void onClick(View v) {

					OilCharge();
					line.setVisibility(View.GONE);
					back.setVisibility(View.VISIBLE);
					title.setText("恭喜你，充值成功");
					text.setText("\n\n\n" + "充值金额  ；   " + jifen.monney
							+ "\n\n\n充值卡号" + jifen.number);
				}
			});
			break;
		case 3:
			back.setVisibility(View.VISIBLE);
			line.setVisibility(View.GONE);
			title.setText("绑定提示");
			text.setText("恭喜您，油卡绑定成功");
			back.setOnClickListener(new View.OnClickListener() {

				@Override
				public void onClick(View v) {
					OilDialog.dismiss();
				}
			});
			
			break;

		default:
			break;

		}
		back.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				OilDialog.dismiss();
			}
		});
		cancle.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				OilDialog.dismiss();
			}
		});
		OilDialog.show();
	}

	void isCharge() {
		jifen.monney=ConsumJiFen.getText().toString();
		System.out.println("姓名   " + jifen.Name + "积分   " + jifen.monney
				+ "油卡ID" + jifen.number);
		if(jifen.Name != null && !"".equals(jifen.Name)&&jifen.monney != null && !"".equals(jifen.monney)&&Long.parseLong(jifen.monney) < Long.parseLong(sumjifen)&&Long.parseLong(jifen.monney) > 200&&Long.parseLong(jifen.monney) >200&&jifen.number != null && !"".equals(jifen.number)){
			tishi.setVisibility(View.GONE);
			createDialog(0, 2);
		}else if(jifen.Name == null || "".equals(jifen.Name)){
			tishi.setText("您还没输入姓名");
		}else if(jifen.monney == null || "".equals(jifen.monney)){
			tishi.setText("您还没输入金额");
		}else if(Long.parseLong(jifen.monney) >Long.parseLong(sumjifen)){
			tishi.setText("您消耗的积分大于您的总积分");
		}else if(Long.parseLong(jifen.monney) <200){
			tishi.setText("您没输入积分必须大于200");
		}else if(jifen.number == null ||"".equals(jifen.number)){
			tishi.setText("您还没输入油卡号");
		}
//		if (jifen.Name != null && !"".equals(jifen.Name)) {
//			if (jifen.monney != null && !"".equals(jifen.monney)) {
//				if (Long.parseLong(jifen.monney) < Long.parseLong(sumjifen)&&Long.parseLong(jifen.monney) > 200) {
//					tishi.setVisibility(View.GONE);
//					createDialog(0, 2);
//
//				}
//			} else if ("".equals(jifen.monney)) {
//				tishi.setVisibility(View.VISIBLE);
//				tishi.setText("*请选择您的积分");
//			} else if (Long.parseLong(jifen.monney) < 200) {
//				tishi.setVisibility(View.VISIBLE);
//				tishi.setText("*您填写的积分必须大于200");
//			} else if ("".equals(jifen.Name)) {
//				tishi.setVisibility(View.VISIBLE);
//				tishi.setText("*请填写您的姓名");
//			}
//
//		} else {
//			tishi.setVisibility(View.VISIBLE);
//			tishi.setText("*请输入您的油卡号");
//		}
	}

	// 提交订单 时封装信息
	class oil_order {
		String number;
		String monney;
		String consumeJiFen = "20000";
	}

	void back(View view) {
		ImageView back = (ImageView) view.findViewById(R.id.title_back_btn);
		back.setOnClickListener(this);
	}

	/**
	 * 取消对话框
	 * 
	 * @param response
	 */
	void cancleDialog(JSONObject response) {
		try {
			if (response.getString("flag").equals("success")) {
				ProgressDialogUtil.cancleProgressDialog(dialog);
			} else if (response.getString("flag").equals("fail")) {
				ProgressDialogUtil.cancleProgressDialog(dialog);
				Toast.makeText(context, "绑定失败，请重试", Toast.LENGTH_SHORT).show();
			}
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 * 异步线程 计算对话框时间 超出10秒自动关闭
	 * 
	 * @author Administrator
	 */
	class MyThread extends Thread {
		int i = 0;

		@Override
		public void run() {
			while (i < 10) {
				try {
					sleep(1000);
					i++;
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			Message msg = new Message();
			msg.what = 1;
			handler.sendMessage(msg);

		}
	}

	/**
	 * 处理时间 取消对话框
	 * 
	 * @author Administrator
	 * 
	 */
	class MyHandler extends Handler {
		@Override
		public void handleMessage(Message msg) {
			if (msg.what == 1) {
				ProgressDialogUtil.cancleProgressDialog(dialog);
			}
		}

	}

	class JiFenOrder {
		String number = "200";
		String monney = "20000";
		String JiFeng;
		String Name;
		String Id;

	}

	/**
	 * 
	 * @author 涂程 注册一个广播 接收由适配器发过来的数据
	 * 
	 */
	class ReceiveBroadCast extends BroadcastReceiver {

		@Override
		public void onReceive(Context context, Intent intent) {
			oild_charge = inflater.inflate(R.layout.oild_new_charge, null);
			OildCardDialog.this.setContentView(oild_charge);
			charge_init();

			LinearLayout line = (LinearLayout) oild_charge
					.findViewById(R.id.list2);
			ListView list = (ListView) oild_charge
					.findViewById(R.id.oild_pay_new_list);

			Button btn = (Button) oild_charge
					.findViewById(R.id.oild_other_charge);

			btn.setVisibility(View.GONE);
			line.setVisibility(View.VISIBLE);
			list_qury.setVisibility(View.GONE);
			jifen.monney = "20000";
			back(oild_charge);
			stack.push(oild_charge);
			getOilJiFen();
			isCharge();

		}

	}

}
